# Mission 6 - final code after obj. 8 from botcore import * from time import sleep thresh = 2000 is_reflective = False SPEED = 30 def drive(left, right): motors.run(LEFT, left) motors.run(RIGHT, right) def calibrate(): global thresh, is_reflective sensors = ls.check(0) line = sensors[2] ground = sensors[0] gap = line - ground if abs(gap) < 500: spkr.pitch(200) sleep(0.2) spkr.off() else: is_reflective = line < ground thresh = round(ground + (gap/2)) spkr.pitch(500) sleep(0.1) spkr.pitch(1000) sleep(0.1) spkr.off() # --- Safety feature --- while True: if buttons.was_pressed(0): break elif buttons.was_pressed(1): calibrate() # === Main program === motors.enable(True) while True: vals = ls.check(thresh, is_reflective) leds.ls(vals) if vals == (1, 0, 0, 0, 0): drive(0, 30) elif vals == (1, 1, 0, 0, 0): drive(15, 30) elif vals == (0, 0, 0, 1, 1): drive(30, 15) elif vals == (0, 0, 0, 0, 1): drive(30, 0) elif vals == (0, 1, 1, 0, 0): drive(35, 40) elif vals == (0, 0, 1, 1, 0): drive(40, 35) elif vals == (0, 0, 1, 0, 0): drive(40, 40)